import { SceneManager } from "../libs/manager/SceneManager";

/**
 * @Author: 陈瑞鹏
 * @Date:   2022-12-03 17:14:08
 * @Last Modified by:   陈瑞鹏
 * @Last Modified time: 2023-01-31 15:51:32
 */
const { ccclass, property } = cc._decorator
@ccclass
export default class itemCom extends cc.Component {

  @property({ type: cc.Sprite, tooltip: "边框" })
  frame: cc.Sprite = null;

  @property({ type: cc.Sprite, tooltip: "图标" })
  icon: cc.Sprite = null;

  @property({ type: cc.Label, tooltip: "名称" })
  nameTxt: cc.Label = null;

  @property({ type: cc.Node, tooltip: "是否解锁" })
  isLock: cc.Node = null;

  @property({ type: cc.Node, tooltip: "是否出战" })
  isWar: cc.Node = null;

  @property({ type: cc.ProgressBar, tooltip: "碎片进度" })
  sPro: cc.ProgressBar = null;

  @property({ type: cc.Label, tooltip: "碎片数量" })
  sNum: cc.Label = null;

  private _data = null;

  protected onLoad(): void {

  }

  protected onEnable(): void {

  }

  public drawUi(data) {
    this._data = data;
    let that = this;
    cc.resources.load(data.iconUrl, cc.SpriteFrame, (err, sp: cc.SpriteFrame) => {
      if (err) return;
      that.icon.spriteFrame = sp;
    })
    let frameUrl = "frame_" + data.quality;
    cc.resources.load(frameUrl, cc.SpriteFrame, (err, sp: cc.SpriteFrame) => {
      if (err) return;
      that.frame.spriteFrame = sp;
    })

    this.isLock.active = data.isLock;
    this.isWar.active = data.isWar;
    this.nameTxt.string = data.name;
    // console.log(this.sNum);
    this.sNum.string = `碎片:${data.fragment}`;
  }

  /**
   * 打开详情
   */
  onClick() {
    SceneManager.getInstance().pushLayer("detailLayer", this._data);
  }
}